<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading"><h3 class="panel-title">物流计划单列表</h3></div>
            <div class="panel-body">
                <form action="" method="GET">
                    <div class="container-fluid">

                        <div class="col-sm-12 col-md-4  add-space">
                            <div class="input-group input-group-md">
                                <select name="codetype" class="form-control" style="width:40%" >
                                    <option value="transport_plan_code"
                                    <?php if(isset($_GET['codetype'])&&$_GET['codetype']=='transport_plan_code'){ echo ' selected';}?>
                                    >物流计划单号</option>
                                    <option value="contract_no"
                                    <?php if(isset($_GET['codetype'])&&$_GET['codetype']=='contract_no'){ echo ' selected';}?>
                                    >合同号</option>
                                    <option value="invoice_code"
                                    <?php if(isset($_GET['codetype'])&&$_GET['codetype']=='invoice_code'){ echo ' selected';}?>
                                    >发票号</option>
                                </select>
                                <input type="text" name="transcode" class="form-control" style="width:60%"
                                       value="<?php if(isset($_GET['transcode'])){ echo $_GET['transcode'];}?>">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">承运商服务</span>
                                <select class="chosen-select form-control" tabindex="-1"
                                        data-name-group="common" name='carrier_service' id='carrier_service'>
                                    <option value=""
                                    <?php if(isset($_GET['carrier_service'])&&$_GET['carrier_service']==''){ echo ' selected';}?>>-- 请选择 --</option>
                                    <volist name='carrier_service' id='vo'>
                                        <option value="{$key}"
                                        <?php if(isset($_GET['carrier_service'])&&$_GET['carrier_service']==$key){ echo ' selected';}?>
                                        >{$vo}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">状态</span>
                                <select name='status' id='statuslist' class="form-control">
                                    <option value="all"
                                    <?php if(isset($_GET['status'])&&$_GET['status']=='all'){ echo ' selected';}?>>--请选择--</option>
                                    <option value="50"
                                    <?php if(isset($_GET['status'])&&$_GET['status']=='50'){ echo ' selected';}?>>待发货</option>
                                    <option value="60"
                                    <?php if(isset($_GET['status'])&&$_GET['status']=='60'){ echo ' selected';}?>>已发货</option>
                                    <option value="70"
                                    <?php if(isset($_GET['status'])&&$_GET['status']=='70'){ echo ' selected';}?>>已到货</option>
                                    <option value="100"
                                    <?php if(isset($_GET['status'])&&$_GET['status']=='100'){ echo ' selected';}?>>已取消</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">创建人</span>
                                <input type="text" name="creater" class="form-control"
                                       value="<?php if(isset($_GET['creater'])){ echo $_GET['creater'];}?>">
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-10  add-space">
                            <div class="input-group">
                                <span class="input-group-addon">日期选择</span>
                                <select name="datetype" class="form-control">
                                    <!-- <option value="" class="empty-opt">--请选择--</option> -->
                                    <option value="expected_pickup_time"
                                    <?php if(isset($_GET['datetype'])&&$_GET['datetype']=='expected_pickup_time'){ echo ' selected';}?>
                                    >预计提货时间</option>
                                    <option value="pickup_op_time"
                                    <?php if(isset($_GET['datetype'])&&$_GET['datetype']=='pickup_op_time'){ echo ' selected';}?>
                                    >发货时间</option>
                                    <option value="create_time"
                                    <?php if(isset($_GET['datetype'])&&$_GET['datetype']=='create_time'){ echo ' selected';}?>
                                    >物流计划创建时间</option>
                                </select>
                                <span class="input-group-addon fix-border fix-padding"></span>
                                <input class="form-control form-date" type="text" name="start_time"
                                       value="<?php if(isset($_GET['start_time'])){ echo $_GET['start_time'];}?>"/>
                                <span class="input-group-addon fix-border fix-padding"><span
                                        class="icon-calendar"></span></span>
                                <input class="form-control form-date" type="text" name="end_time"
                                       value="<?php if(isset($_GET['end_time'])){ echo $_GET['end_time'];}?>"/>
                            </div>
                        </div>
                        <div class="col-md-3 add-space">
                            <input type="submit" value="查询" class="btn btn-primary">
                            <input type="submit" name="exportall" id="exportall" value="导出全部" class="btn btn-info">
                            <input type="submit" name="downall" id="downall" value="下载FBA物流计划单" class="btn btn-info">
                        </div>
                        <div class="col-md-3 add-space">
                        <input type="submit" name="downloadSendData" id="downloadSendData" value="仓储下载FBA待发货数据(默认为当天待发货数据)" class="btn btn-info">
                        </div>
                    </div>

                </form>
                <div class="clearfix"></div>
                <hr>
                <form action="" method="post" name="trans_list" id="trans_list">

                    <div class="fixed-table-toolbar b10">

                        <div class="fixed-table-toolbar b10">

                            <button type="button" name="addTransPlan" id="addTransPlan" class="btn">添加物流计划单</button>
                            <input type="hidden" name="transplans" id="transplans" value="">
                            <input type="submit" name="checked" id="export" value="导出选中" class="btn">
                            <!-- <input type="submit" name="checked" id="markship" value="标记发货" class="btn"> -->

                        </div>
                    </div>
                    <div style="min-width:1000px;max-width:100%;overflow-x:scroll">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th>
                                <input id="checkAll" type="checkbox"/>
                                <!-- <button onclick="chkall(document.trans_list,'all');">全选</button>
                                /
                                <button href="#bottom" onclick="chkall(document.trans_list,'none');">取消</button> -->
                            </th>
                            <th>序号</th>
                            <th>状态</th>
                            <th>物流计划单号</th>
                            <th>合同号</th>
                            <th>发票号</th>
                            <th>入仓号/柜号</th>
                            <th>承运商服务</th>
                            <th>创建人</th>
                            <th><a style="cursor:pointer;">创建时间</a></th>
                            <th>司机姓名（电话）</th>
                            <th>车牌号</th>
                            <th>提单号/快递单号</th>
                            <th>封条号</th>
                            <th>预计提货时间</th>
                            <th>发货人</th>
                            <th><a style="cursor:pointer;">发货时间</a></th>
                            <th>到港时间</th>
                            <th>起飞时间</th>
                            <th>到目的地时间</th>
                            <th>清关时间</th>
                            <th>派送时间</th>
                            <th>包裹信息</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="pageData">
                        <volist name="transresult" id="vo">
                            <tr>
                                <td><input type="checkbox" name="check" value="{$vo.id}"></td>
                                <td>{$i}</td>
                                <td>{$vo.status}</td>
                                <td>{$vo.transport_plan_code}</td>
                                <td>{$vo.contract_no}</td>
                                <td>{$vo.invoice_code}</td>
                                <td>{$vo.certificate_code}</td>
                                <td>{$vo.carrier_service_id}</td>
                                <td>{$vo.create_user_id}</td>
                                <td>{$vo.create_time}</td>
                                <td>{$vo.ori_driver_name}<br>({$vo.ori_driver_tel})</td>
                                <td>{$vo.ori_license_plate_num}</td>
                                <td>{$vo.ori_tracking_num}</td>
                                <td>{$vo.certificate_code}</td>
                                <td>{$vo.expected_pickup_time}</td>
                                <td>{$vo.pickup_op_user_id}</td>
                                <td>{$vo.pickup_op_time}</td>
                                <td>{$vo.arrive_port_date}</td>
                                <td>{$vo.take_off_date}</td>
                                <td>{$vo.arrive_time}</td>
                                <td>{$vo.customs_clearance_date}</td>
                                <td>{$vo.delivery_date}</td>
                                <td onclick="chk_tr_display('chk_tr_{$i}','act_{$i}')" id="pkg_{$i}" title="点击展开"
                                width="6%">
                                    包裹数:{$vo.sumboxs}<br>
                                    总重量:{$vo.sumweight}<br>
                                    总体积:{$vo.sumvol}
                                </td>
                                <td>
                                    <button style="width:60px;" onclick="chk_tr_display('chk_tr_{$i}','act_{$i}')" 
                                    id="act_{$i}" type="button"
                                            class="btn btn-xs btn-info" value="{$vo.id}">展开
                                    </button><br>
                                    <if condition="$vo.status eq '待发货'">
                                        <button style="width:60px;" name="markship" type="button"
                                                class="btn btn-xs btn-info" value="{$vo.id}">标记发货
                                        </button><br>
                                    <else/>
                                    </if>
                                    <button style="width:60px; margin-bottom:4px;" name="editTransPlan" class="btn 
                                    btn-xs btn-info"
                                            type="button" value="{$vo.id}">物流追踪
                                    </button><br>
                                    <button style="width:60px; margin-bottom:4px;" name="cancelTransPlan" class="btn 
                                    btn-xs btn-info"
                                            type="button" value="{$vo.id}">取消
                                    </button>
                                </td>
                            </tr>
                            <tr style="display:none;" id="chk_tr_{$i}">
                                <td></td>
                                <td colspan="16">
                                    <table>
                                        <tr>
                                            <td>序号</td>
                                            <td>Shipmentid</td>
                                            <!-- <td>SKU</td>
                                            <td>虚拟SKU</td>
                                            <td>产品名称</td>
                                            <td>储位</td>
                                            <td>数量</td>
                                            <td>是否退税</td>
                                            <td>销售员</td>
                                            <td>采购员</td> -->
                                            <th>状态</th>
                                            <th>所属需求批次</th>
                                            <th>账号名</th>
                                            <th>站点</th>
                                            <!--<th>承运商服务</th>-->
                                            <th>中转仓库名</th>
                                            <th>亚马逊目的仓地址</th>
                                            <th>要求到货时间</th>
                                            <th>包裹信息</th>
                                            <td>操作</td>
                                        </tr>
                                        <?php if(is_array($vo['detail'])&&count($vo['detail'])>0){ ?>
                                        <volist name="vo.detail" key="k" id="sub">
                                            <tr>
                                                <td>{$k}</td>
                                                <td>
                                                    <a href="{:U('Inbound/Inboundshipmentplan/index')}?shipmentid={$sub.shipmentid}">{$sub.shipmentid}</a>
                                                </td>
                                                <td>{$sub.value}</td>
                                                <td>{$sub.batch_code}</td>
                                                <td>{$sub.account_name}</td>
                                                <td>{$sub.shorthand_code}</td>
                                                <td>{$sub.name}</td>
                                                <td><?php if(isset($shiptoaddresses[$sub["ship_to_address_id"]])){ ?>{$shiptoaddresses[$sub["ship_to_address_id"]]}<?php } ?></td>
                                                <td>{$sub.claim_arrive_time}</td>
                                                <td>
                                                    包裹数:{$sub.total_package}<br>
                                                    重量:{$sub.total_weight}<br>
                                                    体积:{$sub.total_capacity}
                                                </td>
                                                <td>
                                                    <if condition="$vo.status eq '待发货'">
                                                        <button style="width:60px;" name="deleteplat" type="button"
                                                                class="btn btn-xs" value="{$sub.shipmentid}">移除
                                                        </button>
                                                        <else/>
                                                    </if>
                                                </td>
                                            </tr>
                                        </volist>
                                        <?php } ?>
                                    </table>
                                </td>
                            </tr>
                        </volist>
                        </tbody>


                    </table>
                </div>
                </form>

                <div class="yema">页码：{$page}/{$pageSize}，总记录：<span>{$total}</span><div class="page 
                pull-right">{$Pager}</div></div>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/javascripts/admin/layer/layer.js"></script>
<script>
    $(document).ready(function () {
        $("#checkAll").click(function () {
            if ($("#checkAll").attr("checked") == "checked") {

                $("input[name='check']").attr("checked", "checked");
            } else {

                $("input[name='check']").removeAttr("checked", "checked");
            }

        });
        var checked = [];
        $("input[name='checked']").click(function () {
            $("input[name='check']:checked").each(function () {
                checked.push($(this).val());
            });
            $("#transplans").val(checked);
            //alert(checked);
            //return false;
        });
        /**
         * 添加
         */
        $('button[name="addTransPlan"]').on('click', function () {
            var url = "{:U('Transportplan/createTransPlan')}";
            /*layer.open({
             type: 2,
             title: '添加渠道优先级',
             shadeClose: false,
             shade: 0.8,
             area: ['800px', '72%'],
             content: url
             })*/
            window.location.href = url;
        })
        /**
         * 修改
         */
        $('button[name="editTransPlan"]').on('click', function () {
            var id = $(this).val();
            var url = "{:U('Transportplan/editTransPlan')}?id=" + id
            layer.open({
                type: 2,
                title: '物流追踪',
                shadeClose: false,
                shade: 0.8,
                area: ['50%', '70%'],
                content: url
            });
        })
        /**
         * 标记发货
         */
        $('button[name="markship"]').on('click', function () {
            var id = $(this).val();
            var url = "{:U('Transportplan/markship')}?id=" + id
            layer.open({
                type: 2,
                title: '标记发货',
                shadeClose: false,
                shade: 0.8,
                area: ['50%', '55%'],
                content: url
            });
        })
        /**
         * 取消物流计划单
         */
        $('button[name="cancelTransPlan"]').on('click', function () {
            var id = $(this).val();
            layer.confirm("确定要取消物流计划单?",
                    {btn: ['确定', '取消']},
                    function () {
                        $.ajax({
                            url: "{:U('Transportplan/cancelTransPlan')}",
                            type: 'post',
                            async: true, //default: true
                            data: {'id': id},
                            dataType: 'json', // default: Intelligent Guess (xml, json, script, or html)
                            success: function (data, textStatus, jqXHR) {
                                if (data == "取消成功") {
                                    alert("物流计划单(" + id + ")已取消.");
                                    location.reload()
                                }
                            }
                        })  //ajax end
                    }
            )   //layer end
        })
        /**
         * 从物流计划单中移除单个平台计划单
         */
        $('button[name="deleteplat"]').on('click', function () {
            var id = $(this).val();
            layer.confirm("确定要移除平台计划单(" + id + ")?",
                    {btn: ['确定', '取消']},
                    function () {
                        $.ajax({
                            url: "{:U('Transportplan/delplat')}",
                            type: 'post',
                            async: true, //default: true
                            data: {'id': id},
                            dataType: 'json', // default: Intelligent Guess (xml, json, script, or html)
                            success: function (data, textStatus, jqXHR) {
                                if (data == "移除成功") {
                                    alert("平台计划单(" + id + ")已移除.");
                                    location.reload()
                                }
                            }
                        })  //ajax end
                    }
            )   //layer end
        })
    })
    function chk_tr_display(tr, a) {
        if (document.getElementById(tr).style.display == 'none') {
            document.getElementById(tr).style.display = '';
            document.getElementById(a).innerHTML = '收起';
        } else {
            document.getElementById(tr).style.display = 'none';
            document.getElementById(a).innerHTML = '展开';
        }
    }
    function chkall(f, t) {
        els = f.elements;
        if (t == 'all') {
            chked = true;
        }
        if (t == 'none') {
            chked = false;
        }
        for (i = 0; i < els.length; i++) {
            if (els[i].type == 'checkbox') {
                els[i].checked = chked;
            }
        }
    }
</script>